package com.sky.mapper.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.enumeration.OperationType;
import com.sky.pojo.Category;
import com.sky.pojo.Dish;
import com.sky.pojo.Setmeal;
import com.sky.pojo.SetmealDish;
import com.sky.service.annotation.AutoFill;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.*;

import java.math.BigDecimal;
import java.util.List;

@Mapper
public interface SetmealMapper {

    /**
     * 根据分类id查询套餐的数量
     * @param id
     * @return
     */
    @Select("select count(id) from setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(Long id);

    /**
     * 新增套餐
     * @param setmeal
     */
    @AutoFill(value = OperationType.INSERT)

    void addSerMeal(Setmeal setmeal);
/*select * from dish left join category c on dish.category_id = c.id where category_id = #{categorlyId}*/
    @Select("select * from dish where category_id = #{categorlyId}")
    List<Dish> selectDishListByCaregorlyId(String categorlyId);

    List<SetmealVO> selectSetMealList(SetmealPageQueryDTO setmealPageQueryDTO);

    @Insert("insert into setmeal_dish (setmeal_id, dish_id, name, price, copies) values (#{setmealId},#{dishId},#{name},#{price},#{copies});")
    void addsetmealDish(SetmealDish dish );
    @Select("select * from category where  id = #{categoryId};")
    List<Category> selectCategoryById(int categoryId);
    @Select("select status from setmeal where id = #{id}; ")
    Integer selectStatusById(Long id,Integer status);
    @Delete("delete from setmeal where id = #{id};")
    void deleteSetMeals(Long id);
    @Select("select count(*) from setmeal_dish where setmeal_id = #{id}")
    int selectSetMealById(Long id);
    @Delete("delete from setmeal_dish where setmeal_id = #{setmealDishId}")
    void deleteSetMealDishById(Long setmealDishId);
    @Select("select id, category_id, name, price, status, description, image, update_time, make_time from setmeal where id = 1")
    SetmealVO selectSetMealInfoById(Long setmealId);
    @Select("select c.name from setmeal s left join category c on s.category_id = c.id where s.id = #{setmealId} ")
    String getCategoryName(Long setmealId);
    @Select("select sd.* from setmeal s left join setmeal_dish sd on s.id = sd.setmeal_id where s.id = #{setmealId};")
    List<SetmealDish> selectSetMealDishById(Long setmealId);

    @Update("update setmeal set status = #{status} where id =#{id}")
    void updateSetmealStatus(int status, String id);
}
